home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / BODI / CONVERT.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  37.5 KB  |  1,156 lines

  1. /**************************************************************************/
  2. /*  FILE:  CONVERT.C        PROGRAM TITLE: DeskSET II Alpha Version   */
  3. /*  Date Created: 01/07/88                          */ 
  4. /*  Last Modified: 02/10/89                          */
  5. /*                                      */
  6. /*  Description: CONVERSION ROUTINES                      */
  7. /*  Routines:                                  */
  8. /*       o  hmutopix()          - Horizontal Machine Units to Pixels.     */
  9. /*    o  vmutopix()          - Vertical Machine Units to Pixels.       */
  10. /*    o  hpixtomu()          - Horizontal Pixels to Machine Units.     */
  11. /*    o  vpixtomu()          - Vertical Pixels to Machine Units.      */
  12. /*    o  scrntomu()          - Screen Pixels to Machine Units.      */
  13. /*    o  mutoscrn()          - Machine Units to Screen Pixels.      */
  14. /*    o  mutomem()           - Machine Units to Scanner Pixels      */
  15. /*    o  memtomu()           - Scanner to Machine Units          */
  16. /*    o  scale()             - Scale up/down MU to scrn/scrn to Mu     */
  17. /*    o  scale_xy()        - Scale up/down MU to scrn/scrn to Mu      */
  18. /*    o  itoa()              - Integer to ASCII conversion          */
  19. /*    o  reverse()           - Reverse text string - Used by itoa()    */
  20. /*    o  scale_me()         - scale up/down - used by scale()      */
  21. /*    o  mutopage()          - convert MU to Preview Page units        */
  22. /*    o  scale_iv()          - scaler for arrows,sliders etc.       */
  23. /*                  (ok, its really a muldiv...)          */
  24. /*      o  scale_v()        - another muldiv              */
  25. /*    o  mutolas()           - Machine Units to Laser Coordinates      */
  26. /*    o  pttomu()            - Point Size to Machine Units conversion  */
  27. /*    o  get_scale_num()    - Get current scale size (quick and dirty)*/
  28. /*                - based upon a muldiv for size to fit      */
  29. /*    o  scale_request()    - Get a scale number from table          */
  30. /*    o  scrn2mu()        - Scrn to Mu conversion - PADJCNT specific*/
  31. /*    o do_trans_scale()    - Translation and scaling for typed coords*/
  32. /*    o case12_scale()    - scale for opcodes 1 and 2 for typed "   */
  33. /*    o scale_prim_coord()                          */
  34. /*    o mutopt()                              */
  35. /**************************************************************************/
  36.  
  37. /**************************************************************************/
  38. /* HISTORY                                  */
  39. /*                                      */
  40. /* 11/07/89  - comment out scale_me() C function              */
  41. /*         - convert all calls to scale_me() to _scaleme()          */
  42. /*           which can be found in fast.s                  */
  43. /*         - scale()    - replace scale_me() with scaleme()          */
  44. /*           scale_xy() - replace scale_me() with scaleme()          */
  45. /*           scale_me() - commented out                  */
  46. /*                                      */
  47. /* 11/07/89  - comment out scale_v()                      */
  48. /*         - convert all calls to scale_v() with scaler()          */
  49. /*           which can be found in fast.s                  */
  50. /*         - scale_v()  - commented out                  */
  51. /*                                      */
  52. /* 11/07/89  - comment out scale_iv()                      */
  53. /*         - convert all calls to scale_iv() with scaler()          */
  54. /*           scrntomu()   - replace scale_iv() with scaler()          */
  55. /*           mutoscrn()   - replace scale_iv() with scaler()          */
  56. /*           mutopage()   - replace scale_iv() with scaler()          */
  57. /*           get_scaled() - replace scale_iv() with scaler()          */
  58. /*           scrn2mu()    - replace scale_iv() with scaler()            */
  59. /*           do_trans_scale() - "     "        "          */
  60. /*           case12_scale - replace scale_iv() with scaler()          */
  61. /*           scale_prim_coord()   "       "      "     "            */
  62. /*           scale() - changed scaler variable to scd              */
  63. /*             so as not to even remotely interfere          */
  64. /*                                      */
  65. /* 11/07/89  - comment out hmutopix(). Replaced with hmupix() in fast.s   */
  66. /*         - Replace hmutopix() calls with hmupix()              */
  67. /*           mutoscrn()   -   replace hmutopix() with hmupix()      */
  68. /*           mutomem()    -   replace hmutopix() with hmupix()          */
  69. /*           mutopage()   -   replace hmutopix() with hmupix()          */
  70. /*           mutolas()    -   replace hmutopix() with hmupix()          */
  71. /*           get_scale_num()    "        "         "     "              */
  72. /*                                      */
  73. /* 11/07/89  - comment out vmutopix(). Replaced with vmupix() in Fast.s   */
  74. /*         - Replace vmutopix() calls with vmupix()              */
  75. /*           mutoscrn()   -   replace vmutopix() with vmupix()      */
  76. /*           mutomem()    -   replace vmutopix() with vmupix()          */
  77. /*           mutopage()   -   replace vmutopix() with vmupix()          */
  78. /*           mutolas()    -   replace vmutopix() with vmupix()          */
  79. /*           get_scale_num()    "        "         "     "              */
  80. /*                                      */
  81. /* 11/07/89  - comment out hpixtomu(). Replaced with hpixmu() in fast.s   */
  82. /*           Replace hpixtomu() calls with hpixmu();              */
  83. /*           scrntomu() - Replace hpixtomu() with hpixmu()          */
  84. /*           memtomu()  - Replace hpixtomu() with hpixmu()          */
  85. /*           scrn2mu()  - Replace hpixtomu() with hpixmu()          */
  86. /*                                       */
  87. /* 11/07/89  - comment out vpixtomu(). Replaced with vpixmu() in fast.s   */
  88. /*           Replace vpixtomu() calls with vpixmu()              */
  89. /*           scrntomu() - Replace vpixtomu() with vpixmu()          */
  90. /*           memtomu()  - Replace vpixtomu() with vpixmu()          */
  91. /*           scrn2mu()  - Replace vpixtomu() with vpixmu()          */
  92. /**************************************************************************/
  93.  
  94.  
  95. /**************************************************************************/
  96. /* INCLUDE FILES                              */
  97. /**************************************************************************/
  98. #include "define.h"
  99. #include "deskset2.h"
  100. #include <obdefs.h>
  101. #include "gemdefs.h"
  102.  
  103. /**************************************************************************/
  104. /* DEFINES                                  */
  105. /**************************************************************************/
  106.  
  107.  
  108. /**************************************************************************/
  109. /* EXTERNALS                                  */
  110. /**************************************************************************/
  111. extern int sxres;                   /* screen x resolution */
  112. extern int syres;                   /* screen y resolution */
  113.  
  114. extern GRECT dpwork;                   /* window work area    */
  115. extern GRECT pwork;                   /* Preview window work */
  116.  
  117. extern int pagew,pageh;                   /* Current page width  */
  118.                            /* and height - pixels */
  119. extern int dummy;                   /* well, dummy         */
  120. extern GRECT page_area;                   /* blit area in preview*/
  121.                            /* area...          */
  122.                            /* in MU units...      */
  123. extern int pxyarray[];                   /* temp variable       */
  124. extern int pxy[];                   /* storage...      */
  125. extern int ptsarray[];                   /* interface array     */
  126.                            /* for conversions     */
  127. extern int alt_offset;
  128. extern int print_flag;
  129. extern int unit_type;
  130. extern double modf();
  131. extern int snap_to_grids;
  132. extern int deltax,deltay;
  133. extern unsigned long region_ptr;
  134. extern unsigned long gl_region_ptr;
  135. extern int count,wmode;
  136. extern long get_regart();
  137. extern int deferhj;
  138.  
  139. /**************************************************************************/
  140. /* GLOBAL VARIABLES                              */
  141. /**************************************************************************/
  142. int hpage_size;            /* Current Horizontal Page Size (MU)      */
  143. int vpage_size;            /* Current Vertical Page Size (MU)        */
  144.  
  145. int view_size;            /* Current Page Scale Size          */
  146. int curr_page;            /* Current Region Page              */
  147.  
  148. int tmpx,tmpy;            /* Several temp variables that are used   */
  149. int dumb;
  150.  
  151. int zdevice;            /* index for which device..          */
  152.                 /* Screen = 0, SCANNER = 1, Preview = 2   */
  153.                                 /* Laser = 3...                  */
  154. int axdpi[4]     = {80,80,80,300};
  155. int aydpi[4]     = {80,80,80,300};
  156. int half_xdpi[4] = {40,40,40,150};/* Screen, Scanner, Preview Laser 1/2xdpi*/
  157. int half_ydpi[4] = {40,40,40,150};/* Screen, Scanner, Preview Laser 1/2ydpi*/
  158.  
  159.  
  160. /**************************************************************************/
  161. /* Function:    hmutopix()                          */
  162. /* Description: Horizontal Machine Units to Horizontal Pixel Conversion   */
  163. /* INPUT : munits  - Machine Units (Horizontal)                    */
  164. /* OUTPUT: returns the number of horizontal pixels              */
  165. /*        Calculation is based upon: o horizontal dpi              */
  166. /*                      o 18 mu per point              */
  167. /*                      o 72 pt per inch              */
  168. /* GLOBALS:   axdpi[] - array containing dpi of destination device      */
  169. /*          zdevice- index into xdpi array                  */
  170. /* Commented out 11/07/89 CJG - replaced with hmupix() in fast.s      */
  171. /**************************************************************************/
  172. /*
  173. int hmutopix(munits)
  174. int munits;
  175. {
  176.      long tmp;
  177.  
  178.      tmp = (long)axdpi[zdevice] * (long)munits;
  179.      munits = ((tmp % 1296L) > 648L);
  180.      tmp /= 1296L;
  181.      return((int)tmp + munits);
  182. }
  183. */
  184.  
  185.  
  186. /**************************************************************************/
  187. /* Function:    vmutopix()                          */
  188. /* Description: Vertical Machine Units to Vertical Pixel Conversion      */
  189. /* INPUT : munits - Machine Units (Vertical)                  */
  190. /* OUTPUT: returns the number of vertical pixels              */
  191. /*        Calculation is based upon: o vertical dpi              */
  192. /*                      o 16 mu per point              */
  193. /*                      o 72 pt per inch              */
  194. /* GLOBALS:   aydpi[] - array containing dpi of destination device      */
  195. /*          zdevice- index into ydpi array                  */
  196. /* Commented out 11/07/89 CJG. Replaced with vmupix() in fast.s          */
  197. /**************************************************************************/
  198. /*
  199. vmutopix(munits)
  200. int munits;
  201. {
  202.     long tmp;
  203.  
  204.     tmp = (long)aydpi[zdevice] * (long)munits;
  205.     munits = ((tmp % 1152L) > 576L);
  206.     tmp /= 1152L;
  207.     return((int)tmp + munits);
  208. }
  209. */
  210.  
  211.  
  212.  
  213.  
  214. /**************************************************************************/
  215. /* Function:     hpixtomu()                          */
  216. /* Description: Pixel to Horizontal Machine Unit Conversion          */
  217. /* INPUT : pixels - Horizontal Pixel units                  */
  218. /* OUTPUT: returns the number of Horizontal Machine Units          */
  219. /*        Calculation is based upon: o horizontal dpi              */
  220. /*                      o 18 mu per point              */
  221. /*                      o 72 pt per inch              */
  222. /* GLOBALS:   axdpi[] - array containing dpi of destination device      */
  223. /*          half_xdpi - array containin 1/2dpi of destination device    */
  224. /*              (used for defining rounding up/down... )      */
  225. /*          zdevice- index into xdpi array                  */
  226. /* Commented out 11/07/89 CJG. Replaced with hpixmu() in fast.s          */
  227. /**************************************************************************/
  228. /*
  229. hpixtomu(pixels)
  230. int pixels;
  231. {
  232.    long tmp;
  233.  
  234.    tmp = (long)pixels * 1296L;
  235.    pixels = ((tmp % (long)axdpi[zdevice]) > (long)half_xdpi[zdevice]);
  236.    tmp /= (long)axdpi[zdevice];
  237.    return((int)tmp + pixels);
  238. }
  239. */
  240.  
  241.  
  242.  
  243. /**************************************************************************/
  244. /* Function:    vpixtomu()                          */
  245. /* Description: Vertical Pixel to Vertical Machine Unit Conversion      */
  246. /* INPUT : pixels - Vertical Pixel units                  */
  247. /* OUTPUT: returns the number of Vertical Machine Units              */
  248. /*        Calculation is based upon: o horizontal dpi              */
  249. /*                      o 16 mu per point              */
  250. /*                      o 72 pt per inch              */
  251. /* GLOBALS:   aydpi[] - array containing dpi of destination device      */
  252. /*          half_ydpi[] - array containing 1/2 dp of destination device */
  253. /*                (used for rounding up/down...)          */
  254. /*          zdevice- index into ydpi array                  */
  255. /* Commented out 11/07/89 CJG. Replaced with vpixtomu() in fast.s      */
  256. /**************************************************************************/
  257. /*
  258. vpixtomu(pixels)
  259. int pixels;
  260. {
  261.      long tmp;
  262.  
  263.      tmp = (long)pixels * 1152L;
  264.      pixels = ((tmp % (long)aydpi[zdevice]) > (long)half_ydpi[zdevice]);
  265.      tmp /= (long)aydpi[zdevice];
  266.      return((int)tmp + pixels);
  267. }
  268. */
  269.    
  270.  
  271.  
  272. /**************************************************************************/
  273. /* Function:    scrntomu()                          */
  274. /* Description: Converts Screen Coordinates to Machine Unit Coordinates   */
  275. /* INPUT:  ox,oy -  Screen Coordinates (Pixels)                  */
  276. /*         nx,ny -  Pointers returning Machine Unit Positions          */
  277. /*       flag  -  Flag  0 - Adjust for window offsets              */
  278. /*                  1 - Do Not Adjust for window offsets          */
  279. /*              Vertices need to be adjusted, lengths do not.   */
  280. /* OUTPUT: nx,ny contain new coordinate positions in machine units      */
  281. /* GLOBALS:  zdevice - defines index for destination device used to get   */
  282. /*               the devices dots per inch resolution          */
  283. /*         pwork   - GRECT structure of preview window work area.       */
  284. /*         pagew   - width of page in pixels on the screen          */
  285. /*         pageh   - height of page in pixels on the screen          */
  286. /*         hpage_size - horizontal page size in machine units          */
  287. /*         vpage_size - vertical page size in machine units          */
  288. /*         page_area  - GRECT defining blit rectangle in Preview buffer */
  289. /*            - page_area.g_x and page_area.g_y defines the     */
  290. /*              current offset of the scrolled preview window   */
  291. /*         view_size  - current view mode - PACTUAL etc...          */
  292. /**************************************************************************/
  293. scrntomu(ox,oy,nx,ny,flag)
  294. int ox,oy;                    /* Old x,y vertice      */
  295. int *nx,*ny;                    /* New adjusted vertice   */
  296. int flag;                    /* scale direction flag   */
  297. {
  298.          int tmpx;
  299.          int tmpy;
  300.      int hwidth;
  301.      
  302.  
  303.          tmpx    = ox;                /* save for later...      */
  304.          tmpy    = oy;
  305.      zdevice = SCREEN;            /* Device destination     */
  306.  
  307.          if(!flag)
  308.          {
  309.          tmpx -= dpwork.g_x;        /* adjust for work offset */
  310.          tmpy -= dpwork.g_y;        /* of the window...       */
  311.          }
  312.  
  313.  
  314.          if((view_size == PSIZE) ||        /* Want Size to Fit       */
  315.             (view_size == PADJCNT))
  316.          {
  317.         hwidth = ((view_size == PADJCNT) ? (hpage_size * 2) : (hpage_size));
  318.         *nx = scaler(tmpx,hwidth,pagew);  
  319.         *ny = scaler(tmpy,vpage_size,pageh);
  320.  
  321.         if(!flag && (view_size == PADJCNT) && (*nx > hpage_size))
  322.         {
  323.         alt_offset = TRUE;
  324.         *nx -= hpage_size;
  325.         }
  326.         else
  327.         alt_offset = FALSE;
  328.                             
  329.          }
  330.          else                    /* otherwise all others   */
  331.          {
  332.         alt_offset = FALSE;
  333.             scale_xy(&tmpx,&tmpy,1);
  334.             *nx = hpixmu(tmpx);
  335.         *ny = vpixmu(tmpy);
  336.  
  337.             if(!flag)                /* adjust for the scrolled*/
  338.         {                    /* offset off of the      */
  339.                 *nx += page_area.g_x;        /* window          */
  340.                 *ny += page_area.g_y;        /* be adjusted...         */
  341.             }                        
  342.          }
  343.  
  344. }
  345.  
  346.  
  347.  
  348.  
  349. /**************************************************************************/
  350. /* Function:    mutoscrn()                          */
  351. /* Description: Machine Units to Screen Coordinate Conversion          */
  352. /* INPUT:        ox,oy - Oldx Machine Unit Positions              */
  353. /*        nx,ny - New Screen Coordinates                  */
  354. /*        flag  - 0 - Add workx and worky for offsets.          */
  355. /*            1 - Don't Add workx and worky offsets.          */
  356. /*            Vertices need to be adjusted, lengths do not.     */
  357. /* OUTPUT: nx,ny contain new coordinate positions in pixel units      */
  358. /* GLOBALS:  zdevice - defines index for destination device used to get   */
  359. /*               the devices dots per inch resolution          */
  360. /*         pwork   - GRECT structure of preview window work area.       */
  361. /*         pagew   - width of page in pixels on the screen          */
  362. /*         pageh   - height of page in pixels on the screen          */
  363. /*         hpage_size - horizontal page size in machine units          */
  364. /*         vpage_size - vertical page size in machine units          */
  365. /*         page_area  - GRECT defining blit rectangle in Preview buffer */
  366. /*            - page_area.g_x and page_area.g_y defines the     */
  367. /*              current offset of the scrolled preview window   */
  368. /*         view_size  - current view mode - RCS numbers PACTUAL etc...  */
  369. /**************************************************************************/
  370. mutoscrn(ox,oy,nx,ny,flag)
  371. int ox,oy;
  372. int *nx,*ny;
  373. int flag;
  374. {
  375.        int txoffset,tyoffset;
  376.        int hwidth;
  377.  
  378.        tmpx    = ox;
  379.        tmpy    = oy;
  380.        zdevice = SCREEN;
  381.             
  382.        if((view_size == PSIZE) ||        /* Size to Fit...        */
  383.       (view_size == PADJCNT))
  384.        {
  385.         hwidth = ((view_size == PADJCNT)?(hpage_size * 2):(hpage_size));
  386.         *nx = scaler(pagew,tmpx,hwidth);
  387.         *ny = scaler(pageh,tmpy,vpage_size);
  388.        }
  389.        else                    /* All others...         */
  390.        {
  391.  
  392.            *nx = hmupix(tmpx);            /* scale the data...     */
  393.        *ny = vmupix(tmpy);
  394.            scale_xy(nx,ny,0);
  395.  
  396.            if(!flag)                /* and adjust for offset */
  397.            {                    /* of scrolling.  Note   */
  398.           txoffset = page_area.g_x;
  399.           tyoffset = page_area.g_y;
  400.           
  401.               txoffset = hmupix(txoffset);
  402.               tyoffset = vmupix(tyoffset);
  403.               scale_xy(&txoffset,&tyoffset,0);
  404.               *nx -= txoffset;
  405.               *ny -= tyoffset;              
  406.            }                    /* only...         */
  407.        }
  408.  
  409.        if(!flag)                /* adjust for the offset */
  410.        {                    /* of the work window    */
  411.        *nx += dpwork.g_x;            /* Again, only vertices  */
  412.            *ny += dpwork.g_y;            /* need apply...         */
  413.        }
  414.  
  415. }
  416.  
  417.  
  418.  
  419.  
  420. /**************************************************************************/
  421. /* Function:    mutomem()                          */
  422. /* Description:    Converts Machine Units to Scanner Coordinates            */
  423. /* IN  : ox,oy  -  MU position to convert to the scan buffer.          */
  424. /* OUT : nx,ny  -  pixel positions in the scan buffer.              */
  425. /* NOTE: scan buffer is configured always for actual size...           */
  426. /*     with LEGAL size paper                          */
  427. /* GLOBALS:   zdevice - defines index for destination device used to get  */
  428. /*            the dots per inch resolution              */
  429. /**************************************************************************/
  430. mutomem(ox,oy,nx,ny)
  431. int ox,oy;
  432. int *nx,*ny;
  433. {
  434.     zdevice = SCANNER;
  435.     *nx = hmupix(ox);
  436.     *ny = vmupix(oy);
  437. }
  438.  
  439.  
  440.  
  441.  
  442. /**************************************************************************/
  443. /* Function:    memtomu()                          */
  444. /* Description:    Converts Scanner Coordinates to Machine Units              */
  445. /*                                      */
  446. /* IN : ox,oy   - scan buffer pixel positions to convert to MU          */
  447. /* OUT: nx,ny   - Converted machine units coordinates              */
  448. /* Note: Scan buffer is configured always for actual size...          */
  449. /*     with LEGAL size paper                          */
  450. /* GLOBALS:  zdevice - defines index for destination device used to get   */
  451. /*               the dots per inch resolution              */
  452. /**************************************************************************/
  453. memtomu(ox,oy,nx,ny)
  454. int ox,oy;
  455. int *nx,*ny;
  456. {
  457.      zdevice = SCANNER;
  458.      *nx = hpixmu(ox);
  459.      *ny = vpixmu(oy);
  460.      if((curr_page % 2) && (view_size == PADJCNT) && !print_flag)
  461.             *nx += hpage_size;
  462. }
  463.  
  464.  
  465.  
  466.  
  467. /**************************************************************************/
  468. /*  Function:     scale()                          */
  469. /*  Description: Scale routine to convert a data pair from:          */
  470. /*         o A percentage to absolute 100% size ( % to MU)      */
  471. /*         o Absolute 100% to any percentage size (MU to %)      */
  472. /*  IN:    tx,ty       - vertice                      */
  473. /*         txoff,tyoff - x and y offset of scrolling.              */
  474. /*       flag        - direction of scaling - up or down.          */
  475. /*             0 - mu to percentage   1 - percentage to mu      */
  476. /*  OUT:   tx,ty       - adjusted vertice                  */
  477. /*         txoff,tyoff - adjusted x and y offset (compensates scrolling      */
  478. /* I believe that this routine is called by only one function.  The others*/
  479. /* use scale_xy() for a better usage of the stack.              */
  480. /**************************************************************************/
  481. scale(tx,ty,txoff,tyoff,flag)
  482. int *tx,*ty;
  483. int *txoff,*tyoff;
  484. int flag;                    /* 0 - mu to percentage   */
  485. {                        /* 1 - percentage to MU   */
  486.       int scd;
  487.  
  488.       scd    = scale_request(view_size);    /* get a scale factor      */
  489.       *tx    = scaleme(*tx,scd,flag);        /* scale them...       */
  490.       *ty    = scaleme(*ty,scd,flag);    
  491.       *txoff = scaleme(*txoff,scd,flag);    
  492.       *tyoff = scaleme(*tyoff,scd,flag);
  493. }
  494.  
  495.  
  496.  
  497.  
  498.  
  499. /**************************************************************************/
  500. /* Function: scale_xy()                              */
  501. /* Description:    same as scale, but used for those who only need to handle */
  502. /*        vertices and nothing else.                  */
  503. /* IN:  tx,ty - pointers to the vertice                      */
  504. /*    flag  - direction of conversion                      */
  505. /*        o  0 = 100% to any percentage (MU to %)              */
  506. /*        o  1 = percentage to 100%     (% to MU)              */
  507. /* OUT: tx,ty are pointers to new numbers.                  */
  508. /**************************************************************************/
  509. scale_xy(tx,ty,flag)
  510. int *tx,*ty;
  511. int flag;                    /* 0 - mu to percentage   */
  512. {                        /* 1 - percentage to MU   */
  513.       int scd;
  514.  
  515.       scd    = scale_request(view_size);    /* get scale factor       */
  516.       *tx    = scaleme(*tx,scd,flag);        /* and scale them...       */
  517.       *ty    = scaleme(*ty,scd,flag);    
  518. }
  519.  
  520.  
  521.  
  522.  
  523. /**************************************************************************/
  524. /*  Function:     itoa()                          */
  525. /*  Description:  Integer to ASCII conversion                  */
  526. /**************************************************************************/
  527. itoa(n,s)
  528. int n;
  529. register char s[];
  530. {
  531.     register int i;
  532.     int sign;
  533.     if((sign = n) < 0)
  534.        n = -n;
  535.     i = 0;
  536.     do
  537.     {
  538.     s[i++] = n % 10 + '0';
  539.     }while(( n /= 10) > 0);
  540.  
  541.     if(sign < 0)
  542.        s[i++] = '-';
  543.     s[i] = '\0';
  544.     reverse(s);
  545. }
  546.  
  547.  
  548.  
  549.  
  550. /**************************************************************************/
  551. /*  Function:    reverse()                          */
  552. /*  Description: reverses a text string. Used by itoa()              */
  553. /**************************************************************************/
  554. reverse(s)
  555. register char s[];
  556. {
  557.      int c;
  558.      register int i,j;
  559.  
  560.      for(i=0,j=strlen(s) - 1; i<j; i++,j--)
  561.      {
  562.           c    = s[i];
  563.           s[i] = s[j];
  564.       s[j] = c;
  565.      }
  566. }
  567.  
  568.  
  569.  
  570.  
  571. /**************************************************************************/
  572. /*  Function:    scale_me()                          */
  573. /*  Description: Performs actual scaling of data.              */
  574. /*         called by scale()                      */
  575. /*  IN:      num    - number to scale                      */
  576. /*         scaler - scale factor                      */
  577. /*         flag   - scale from    0 - mu to percentage          */
  578. /*                          1 - percentage to mu          */
  579. /*  OUT:     returns in D0 the newly scaled number              */
  580. /*  Commented out 11/07/89 CJG - See fast.s for scaleme()          */
  581. /**************************************************************************/
  582. /*
  583. scale_me(num,scaler,flag)
  584. int  num;
  585. int  scaler;
  586. int  flag;
  587. {
  588.       long  tmp;
  589.       int  extra;
  590.       long  half;      
  591.  
  592.       if(!flag)            *scale from full size to percentage  *
  593.       {
  594.            tmp = (long)num * (long)scaler;
  595.            extra = ((tmp % 100L) > 50L);
  596.        tmp /= 100L;
  597.        return((int)tmp + extra);
  598.       }
  599.       else            * scale from percentage to full size *
  600.       {
  601.            half = (long)scaler / 2L;
  602.        tmp = (long)num * 100L;
  603.        extra = ((tmp % (long)scaler) > half);
  604.            tmp /= (long)scaler;
  605.            return((int)tmp + extra);
  606.       }     
  607.  
  608. }
  609. */
  610.  
  611.  
  612.  
  613. /**************************************************************************/
  614. /*  Function:    mutopage()                          */
  615. /*  Description: Scale from MU to Preview Page Memory Driver          */
  616. /*  IN:      ox,oy  - MU units to convert to pixels              */
  617. /*  OUT:     nx,ny  - Returns Pixel units in Preview Page mode          */
  618. /*  GLOBALS: zdevice - defines index for destination device used to get   */
  619. /*               the devices dots per inch resolution          */
  620. /*         pagew   - width of page in pixels on the screen          */
  621. /*         pageh   - height of page in pixels on the screen          */
  622. /*         hpage_size - horizontal page size in machine units          */
  623. /*         vpage_size - vertical page size in machine units          */
  624. /*         view_size  - current view mode - RCS numbers PACTUAL etc...  */
  625. /**************************************************************************/
  626. mutopage(ox,oy,nx,ny,flag)
  627. int ox,oy;
  628. int *nx,*ny;
  629. int flag;
  630. {
  631.        int hwidth;
  632.  
  633.        tmpx = ox;
  634.        tmpy = oy;
  635.  
  636.        zdevice = PREVIEW;
  637.  
  638.        if((view_size == PSIZE) ||        /* Handle Size to Fit     */
  639.       (view_size == PADJCNT))
  640.        {
  641.         hwidth = ((view_size == PADJCNT)?(hpage_size*2):(hpage_size));
  642.         *nx = scaler(pagew,tmpx,hwidth);
  643.         *ny = scaler(pageh,tmpy,vpage_size);
  644.         if(!flag && (curr_page % 2) && (view_size == PADJCNT))
  645.             *nx += pagew/2;
  646.        }
  647.        else                    /* And all others...       */
  648.        {                    /* Scale down appropriately*/
  649.            *nx = hmupix(tmpx);
  650.        *ny = vmupix(tmpy);
  651.            scale_xy(nx,ny,0);
  652.        }
  653. }
  654.  
  655.  
  656.  
  657.  
  658. /**************************************************************************/
  659. /*  Function:    scale_iv()                          */
  660. /*  Description: A muldiv based on input paramters of INT, LONG, LONG     */
  661. /*  IN:      visible  - amount of document visible              */
  662. /*         factor   - new percentage to modify by...              */
  663. /*         total    - total size of document                  */
  664. /*  OUT:     Returns in D0 an adjusted size factor              */
  665. /*  Comment out scale_iv() All calls replaced with scaler()          */
  666. /*  which can be found in fast.s    CJG 11/07/89              */
  667. /**************************************************************************/
  668. /*
  669. scaler(visible,factor,total)
  670. int visible;
  671. int factor;
  672. int total;
  673. {
  674.       long tmp;
  675.       int munits;
  676.       int half;
  677.  
  678.       half = total / 2;
  679.  
  680.       tmp = (long)visible * (long)factor + (long)half;
  681. *      munits = ((tmp % (long)total) > half);*
  682.       tmp /= (long)total;
  683. *      return((int)tmp + munits);*
  684.       return((int)tmp);
  685. }
  686. */
  687.  
  688.  
  689.  
  690.  
  691. /**************************************************************************/
  692. /* Function:     scale_v()                          */
  693. /* Description:  Another MULDIV based on INT, INT, INT              */
  694. /*  IN:      visible  - amount of document visible              */
  695. /*         factor   - new percentage to modify by...              */
  696. /*         total    - total size of document                  */
  697. /*  OUT:     Returns in D0 an adjusted size factor              */
  698. /*  Commented out 11/07/89 CJG. replaced with scaler() in fast.s      */
  699. /**************************************************************************/
  700. /*
  701. scale_v(visible,factor,total)
  702. int visible;
  703. int factor;
  704. int total;
  705. {
  706.       long tmp;
  707.       int  munits;
  708.       long half;
  709.  
  710.       half = ((long)total / 2L);
  711.  
  712.       tmp = (long)visible * (long)factor;
  713.       munits = ((tmp % (long)total) > half);
  714.       tmp /= (long)total;
  715.       return((int)tmp + munits);
  716. }
  717. */
  718.  
  719.  
  720.  
  721. /**************************************************************************/
  722. /* Function:    mutolas()                          */
  723. /* Description:    Converts Machine Units to Laser Driver Coordinates        */
  724. /* IN: ox,oy  - MU position to convert to the laser buffer.          */
  725. /* OUT: nx,ny - pixel positions in the laser buffer.              */
  726. /* NOTE: Laser buffer is configured always for actual size...           */
  727. /* GLOBAL:  zdevice - used to define device mode for conversion routines  */
  728. /**************************************************************************/
  729. mutolas(ox,oy,nx,ny)
  730. int ox,oy;
  731. int *nx,*ny;
  732. {
  733.     zdevice = LASER;
  734.     *nx = hmupix(ox);
  735.     *ny = vmupix(oy);
  736. }
  737.  
  738.  
  739.  
  740. /**************************************************************************/
  741. /* Function:    pttomu()                          */
  742. /* Description:    Point Size Text to Vertical Machine Units.          */
  743. /* IN:   ptsize  - Point Size of Text                      */
  744. /* OUT:  Returns vertical machine units.                  */
  745. /**************************************************************************/
  746. pttomu(ptsize)
  747. {
  748.     return(16*ptsize);
  749. }
  750.  
  751.  
  752.  
  753.  
  754. /**************************************************************************/
  755. /* Function:    get_scale_num()                          */
  756. /* Description: get a scale for the current size to pass to do_text       */
  757. /* IN: size - current viewing mode in RCS units - ie: PACTUAL          */
  758. /* OUT: returns a scale # from 1 to 200                      */
  759. /* GLOBAL:      vpage_size - vertical page size in machine units      */
  760. /*              pwork.g_h  - height of preview work window          */
  761. /**************************************************************************/
  762. get_scale_num(size)
  763. int size;
  764. {
  765.    int hwidth;
  766.    int column;
  767.    int pixw,pixh;
  768.  
  769.    if( (view_size == PSIZE) || (view_size == PADJCNT))
  770.    {
  771.       pixw = hmupix(hpage_size);
  772.       pixh = vmupix(vpage_size);
  773.  
  774.       hwidth = ((view_size == PADJCNT) ? (pixw * 2) : (pixw));
  775.       column = ((view_size == PADJCNT) ? (dpwork.g_w/2) : (dpwork.g_w));
  776.       if(dpwork.g_w <= scaler(dpwork.g_h,hwidth,pixh))
  777.          return(scaler(column,100,pixw));
  778.       else
  779.          return(scaler(dpwork.g_h,100,pixh));
  780.    }
  781.    else
  782.      return(scale_request(size));
  783. }
  784.  
  785.  
  786.  
  787.  
  788. /**************************************************************************/
  789. /* Function:  scale_request()                          */
  790. /* Description: Gets a scale factor from a table between 1 to 200      */
  791. /* IN: size - view mode in RCS units ie: PACTUAL              */
  792. /* OUT: returns scale factor between 1 to 200                  */
  793. /* GLOBAL: scale_set - current setting of user defined mode.          */
  794. /**************************************************************************/
  795. scale_request(size)
  796. int size;
  797. {
  798.       int factor;
  799.  
  800.         switch(size)
  801.         {
  802.           case P50:     factor = 50;
  803.                   break;
  804.  
  805.           case P75:     factor = 75;
  806.                 break;
  807.  
  808.       case PACTUAL: factor = 100;
  809.                 break;
  810.  
  811.           case P200:    factor = 200;
  812.                         break;
  813.         }
  814.         return(factor);
  815. }
  816.  
  817.  
  818.  
  819. /**************************************************************************/
  820. /* Function: scrn2mu()                              */
  821. /* Description: Converts screen coordinates to mu (PADJCNT specific)      */
  822. /**************************************************************************/
  823. scrn2mu(ox,oy,nx,ny,flag,flag2)
  824. int ox,oy;                    /* Old x,y vertice      */
  825. int *nx,*ny;                    /* New adjusted vertice   */
  826. int flag;                    /* scale direction flag   */
  827. int flag2;                    /* 0 = first page      */
  828.                         /* 2 = 2nd page          */
  829. {
  830.          int tmpx;
  831.          int tmpy;
  832.      int hwidth;
  833.      
  834.  
  835.          tmpx    = ox;                /* save for later...      */
  836.          tmpy    = oy;
  837.      zdevice = SCREEN;            /* Device destination     */
  838.  
  839.          if(!flag)
  840.          {
  841.          tmpx -= dpwork.g_x;        /* adjust for work offset */
  842.          tmpy -= dpwork.g_y;        /* of the window...       */
  843.          }
  844.  
  845.  
  846.          if((view_size == PSIZE) ||        /* Want Size to Fit       */
  847.             (view_size == PADJCNT))
  848.          {
  849.         hwidth = ((view_size == PADJCNT) ? (hpage_size * 2) : (hpage_size));
  850.         *nx = scaler(tmpx,hwidth,pagew);  
  851.         *ny = scaler(tmpy,vpage_size,pageh);
  852.  
  853.         if((flag2) && (view_size == PADJCNT) && (!flag) )
  854.         {
  855.         alt_offset = TRUE;
  856.         *nx -= hpage_size;
  857.         }
  858.         else
  859.         alt_offset = FALSE;
  860.                             
  861.          }
  862.          else                    /* otherwise all others   */
  863.          {
  864.             scale_xy(&tmpx,&tmpy,1);
  865.             *nx = hpixmu(tmpx);
  866.         *ny = vpixmu(tmpy);
  867.  
  868.             if(!flag)                /* adjust for the scrolled*/
  869.         {                    /* offset off of the      */
  870.                 *nx += page_area.g_x;        /* window          */
  871.                 *ny += page_area.g_y;        /* be adjusted...         */
  872.             }                        
  873.          }
  874.  
  875. }
  876.  
  877.  
  878.  
  879.  
  880.  
  881. /**************************************************************************/
  882. /* Function: do_trans_scale()                          */
  883. /* Description: Handles typed in coordinates for translation and scaling  */
  884. /**************************************************************************/
  885. do_trans_scale(oldx,oldy,oldwidth,oldheight,newx,newy,newwidth,newheight,type)
  886. int oldx,oldy,oldwidth,oldheight;
  887. int newx,newy,newwidth,newheight;
  888. int type;
  889. {
  890.          int opcode;
  891.     int fflag;
  892.     int fx,fy;
  893.         register int i;
  894.     int toggle;
  895.     int odeltax,ndeltax;
  896.     int odeltay,ndeltay;
  897.         int tempx,tempy;
  898.         int oldrect[4];
  899.  
  900.         oldrect[0] = oldx;
  901.      oldrect[1] = oldy;
  902.     oldrect[2] = oldx + oldwidth - 1;
  903.     oldrect[3] = oldy + oldheight - 1;
  904.  
  905.     if((oldx != newx) || (oldy != newy) || (oldwidth != newwidth)
  906.        || (oldheight != newheight))
  907.     {
  908.        if(snap_to_grids)
  909.        {
  910.         tempx = newx + newwidth;
  911.         tempy = newy + newheight;
  912.         snap_mu(&newx,&newy);
  913.         snap_mu(&tempx,&tempy);
  914.         newwidth  = tempx - newx;
  915.         newheight = tempy - newy;
  916.            }
  917.  
  918.        fx = (  (  (newx - oldx) < 0) ? (-1) : (1));
  919.        fy = (  (  (newy - oldy) < 0) ? (-1) : (1));
  920.  
  921.        deltax = abs(newx - oldx);
  922.        deltay = abs(newy - oldy);
  923.     
  924.        deltax *= fx;
  925.        deltay *= fy;
  926.        
  927.        opcode = get_fprimitive(region_ptr,&count,&wmode);
  928.        fflag = TRUE;
  929.        while(opcode != -1)
  930.        {
  931.         switch(opcode)
  932.         {
  933.             case 3:
  934.             case 4:
  935.             case 0: toggle = TRUE;        /* translate */
  936.                     for(i=0;i<(count*2);i++)
  937.                 {
  938.                    ptsarray[i] += ((toggle) ? (deltax):(deltay));
  939.                    toggle ^= TRUE;
  940.                 }
  941.  
  942.                 i = 0;            /* and scale */
  943.                 while(i<count*2)
  944.                 {
  945.                 odeltax = ptsarray[i] - newx;
  946.                 ndeltax = scaler(odeltax,newwidth,oldwidth);
  947.                 ptsarray[i++] = newx + ndeltax;
  948.  
  949.                 odeltay = ptsarray[i] - newy;
  950.                 ndeltay = scaler(odeltay,newheight,oldheight);
  951.                 ptsarray[i++] = newy + ndeltay;
  952.                 }
  953.  
  954.                 break;
  955.  
  956.             case 1: ptsarray[0] += deltax;    /* translate */
  957.                 ptsarray[1] += deltay;
  958.                             /* and scale */
  959.                 case12_scale(newx,newy,oldwidth,oldheight,
  960.                     newx,newy,newwidth,newheight,1);
  961.                 break;
  962.  
  963.             case 2: ptsarray[0] += deltax;    /* translate */
  964.                 ptsarray[2] += deltax;
  965.                 ptsarray[1] += deltay;
  966.                 ptsarray[3] += deltay;
  967.                             /* and scale */
  968.                 case12_scale(newx,newy,oldwidth,oldheight,
  969.                     newx,newy,newwidth,newheight,2);
  970.                 break;
  971.        
  972.         }    /* end of switch(opcode) */
  973.         update_primitive(opcode,count,wmode,fflag);
  974.         fflag = FALSE;
  975.         opcode = get_nprimitive(&count,&wmode);
  976.        }        /* end of while         */
  977.  
  978.        if(!type)        /* text only */
  979.        {        
  980.         page_redraw(region_ptr);
  981.        }
  982.        else
  983.         update_repel(1,oldrect);
  984.        if(view_size != PADJCNT && !deferhj && gl_region_ptr)
  985.         redraw_area(region_ptr,oldrect,1);
  986.     }
  987.     graf_mouse(0,&dummy);
  988. }
  989.  
  990.  
  991.  
  992.  
  993. /**************************************************************************/
  994. /* Function: case12_scale()                          */
  995. /* Description: Scale for opcodes 1 and 2 for typed in vertices          */
  996. /**************************************************************************/
  997. case12_scale(oldx,oldy,oldw,oldh,newx,newy,neww,newh,flag)
  998. int oldx,oldy,oldw,oldh;
  999. int newx,newy,neww,newh;
  1000. int flag;
  1001. {
  1002.      int odeltax,odeltay;
  1003.      int ndeltax,ndeltay;
  1004.  
  1005.      odeltax = ptsarray[0] - oldx;
  1006.      ndeltax = scaler(odeltax,neww,oldw);
  1007.      ptsarray[0] = newx + ndeltax;
  1008.  
  1009.      odeltay = ptsarray[1] - oldy;
  1010.      ndeltay = scaler(odeltay,newh,oldh);
  1011.      ptsarray[1] = newy + ndeltay;
  1012.  
  1013.      if(flag == 1)
  1014.      {
  1015.          odeltax = ptsarray[2];
  1016.          ndeltax = scaler(odeltax,neww,oldw);
  1017.          ptsarray[2] = ndeltax;
  1018.  
  1019.          odeltay = ptsarray[3];
  1020.          ndeltay = scaler(odeltay,newh,oldh);
  1021.          ptsarray[3] = ndeltay;
  1022.      }
  1023.      else
  1024.      {
  1025.          odeltax = ptsarray[2] - oldx;
  1026.          ndeltax = scaler(odeltax,neww,oldw);
  1027.          ptsarray[2] = newx + ndeltax;
  1028.  
  1029.          odeltay = ptsarray[3] - oldy;
  1030.          ndeltay = scaler(odeltay,newh,oldh);
  1031.          ptsarray[3] = newy + ndeltay;
  1032.      }
  1033. }
  1034.  
  1035.  
  1036.  
  1037.  
  1038. /**************************************************************************/
  1039. /* Function: scale_prim_coord()                              */
  1040. /* Description: Scales primitive coordinates                  */
  1041. /**************************************************************************/
  1042. scale_prim_coord(opcode,oldx,oldy,oldwidth,oldheight,newx,newy,
  1043.          newwidth,newheight,type,count,wmode)
  1044. int opcode;
  1045. int oldx,oldy,oldwidth,oldheight;
  1046. int newx,newy,newwidth,newheight;
  1047. int type;
  1048. int count;
  1049. int wmode; 
  1050. {
  1051.     int fx,fy;
  1052.         register int i;
  1053.     int toggle;
  1054.     int odeltax,ndeltax;
  1055.     int odeltay,ndeltay;
  1056.         int tempx,tempy;
  1057.  
  1058.         int oldrect[4];
  1059.  
  1060.         oldrect[0] = oldx;
  1061.      oldrect[1] = oldy;
  1062.     oldrect[2] = oldx + oldwidth - 1;
  1063.     oldrect[3] = oldy + oldheight - 1;
  1064.  
  1065.     if((oldx != newx) || (oldy != newy) || (oldwidth != newwidth)
  1066.        || (oldheight != newheight))
  1067.     {
  1068.        if(snap_to_grids)
  1069.        {
  1070.         tempx = newx + newwidth;
  1071.         tempy = newy + newheight;
  1072.         snap_mu(&newx,&newy);
  1073.         snap_mu(&tempx,&tempy);
  1074.         newwidth  = tempx - newx;
  1075.         newheight = tempy - newy;
  1076.            }
  1077.  
  1078.        fx = (  (  (newx - oldx) < 0) ? (-1) : (1));
  1079.        fy = (  (  (newy - oldy) < 0) ? (-1) : (1));
  1080.  
  1081.        deltax = abs(newx - oldx);
  1082.        deltay = abs(newy - oldy);
  1083.     
  1084.        deltax *= fx;
  1085.        deltay *= fy;
  1086.  
  1087.         switch(opcode)
  1088.         {
  1089.             case 3:
  1090.             case 4:
  1091.             case 0: toggle = TRUE;        /* translate */
  1092.                     for(i=0;i<(count*2);i++)
  1093.                 {
  1094.                    ptsarray[i] += ((toggle) ? (deltax):(deltay));
  1095.                    toggle ^= TRUE;
  1096.                 }
  1097.  
  1098.                 i = 0;            /* and scale */
  1099.                 while(i<count*2)
  1100.                 {
  1101.                 odeltax = ptsarray[i] - newx;
  1102.                 ndeltax = scaler(odeltax,newwidth,oldwidth);
  1103.                 ptsarray[i++] = newx + ndeltax;
  1104.  
  1105.                 odeltay = ptsarray[i] - newy;
  1106.                 ndeltay = scaler(odeltay,newheight,oldheight);
  1107.                 ptsarray[i++] = newy + ndeltay;
  1108.                 }
  1109.  
  1110.                 break;
  1111.  
  1112.             case 1: ptsarray[0] += deltax;    /* translate */
  1113.                 ptsarray[1] += deltay;
  1114.                             /* and scale */
  1115.                 case12_scale(newx,newy,oldwidth,oldheight,
  1116.                     newx,newy,newwidth,newheight,1);
  1117.                 break;
  1118.  
  1119.             case 2: ptsarray[0] += deltax;    /* translate */
  1120.                 ptsarray[2] += deltax;
  1121.                 ptsarray[1] += deltay;
  1122.                 ptsarray[3] += deltay;
  1123.                             /* and scale */
  1124.                 case12_scale(newx,newy,oldwidth,oldheight,
  1125.                     newx,newy,newwidth,newheight,2);
  1126.                 break;
  1127.        
  1128.         }    /* end of switch(opcode) */
  1129.         update_primitive(opcode,count,wmode,0);
  1130.         recalc_region();
  1131.  
  1132.        if(!type)        /* text only */
  1133.        {
  1134.         page_redraw(region_ptr);
  1135.        }
  1136.        else
  1137.         update_repel(1,oldrect);
  1138.        if(view_size != PADJCNT && !deferhj && gl_region_ptr)
  1139.         redraw_area(region_ptr,oldrect,1);
  1140.     }
  1141.     graf_mouse(0,&dummy);
  1142. }
  1143.  
  1144.  
  1145.  
  1146.  
  1147. /**************************************************************************/
  1148. /* Function: mutopt()                              */
  1149. /* Description:                               */
  1150. /**************************************************************************/
  1151. mutopt(munits)
  1152. int munits;
  1153. {
  1154.    return(munits / 16);
  1155. }
  1156.